package com.yueyang.sojourn.server.service.sojourn.share;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yueyang.sojourn.server.model.enums.StatusEnum;
import com.yueyang.sojourn.server.model.po.SojournShareDetail;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 分账单明细服务
 * @author andy.yang
 * @version v1
 * @summary
 * @Copyright (c) 2019, yueyang Group All Rights Reserved.
 * @since 2020/3/30
 */
@Service
public class SojournShareDetailService {
    @Resource
    SojournShareDetailMapper sojournShareDetailMapper;

    /**
     * 创建分账单明细
     * @param
     * @return
     */
    public int addBatch(List<SojournShareDetail> details){
        return sojournShareDetailMapper.insertBatch(details);
    }

        /**
         * 创建分账单明细
         * @param
         * @return
         */
    public int add(SojournShareDetail detail){
        return sojournShareDetailMapper.insert(detail);
    }

    /**
     * 修改分账单明细状态
     * @param detail
     * @return
     */
    public int updateStatus(SojournShareDetail detail){
        return sojournShareDetailMapper.updateStatus(detail);
    }

    /**
     * @param shareId      所属分账单id
     * @param pageNo      页码
     * @param pageSize    页大小
     * @return
     * @author Andy.yang
     * @summary 订单分页查询
     * @version v1
     * @since 2020-02-19
     */
    public PageInfo<SojournShareDetail> findPage(Long shareId, Integer status,int pageNo, int pageSize) {
        PageInfo<SojournShareDetail> pageInfo = PageHelper.startPage(pageNo, pageSize)
                .doSelectPageInfo(() -> sojournShareDetailMapper.findBy(shareId,status));
        return pageInfo;
    }

    /**
     * @param detailId      分账单明细id
     * @return
     * @author Andy.yang
     * @summary 订单分页查询
     * @version v1
     * @since 2020-02-19
     */
    public SojournShareDetail findById(Long detailId) {
        return sojournShareDetailMapper.selectByPrimaryKey(detailId);
    }

    /**
     * 根据分账单，查询所有分账明细
     * @param shareId      分账单id
     * @return
     * @author Andy.yang
     * @summary 订单分页查询
     * @version v1
     * @since 2020-02-19
     */
    public List<SojournShareDetail> findByShareId(Long shareId) {
        return sojournShareDetailMapper.findBy(shareId, StatusEnum.VALID.getCode());
    }
}
